/**
 * Created by jiang_j on 2017/4/18.
 */

	var http=require('http'),fs=require('fs'),path=require('path')
var  newUrl='http://biaoqingbao.xin/wp-content/uploads/2017/03/1371.jpg'
console.log('111111111111111111')
http.get(newUrl, function(res){
	console.log('2222222222222')
	var imgData = "";

	var fileName = path.basename(newUrl);

	console.log(fileName);

	res.setEncoding("binary"); //一定要设置response的编码为binary否则会下载下来的图片打不开


	res.on("data", function(chunk){
		imgData+=chunk;
	});

	res.on("end", function(){
		fs.writeFile("./" + fileName, imgData, "binary", function(err){
			if(err){
				console.log("down fail");
			}
			console.log("down success");
		});
	});
});